home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.08 Aug 93 / Other AppleScript Samples / Script Application Examples / Quit handler example 2.txt < prev    next >
Encoding:
Text File  |  1993-07-02  |  1.2 KB  |  40 lines  |  [TEXT/ToyS]

  1. property MyData : 0 --The data I store (persistent, remember!)
  2. property OriginalData : 0 --Backup copy of data as of the time I was launched
  3. property modified : false --Has MyData been changed since I was launched?
  4.  
  5. on run
  6.     copy MyData to OriginalData -- Keep a backup
  7.     set modified to false
  8. end run
  9.  
  10. --   Call store from another script to store a piece of data
  11. on store(value)
  12.     if (value ≠ MyData) then
  13.         copy value to MyData
  14.         set modified to true
  15.     end if
  16.     return value
  17. end store
  18.  
  19. --   Call retrieve from another script to retrieve the stored data
  20. on retrieve()
  21.     return MyData
  22. end retrieve
  23.  
  24. --   Confirm quit
  25. on quit
  26.     if modified then
  27.         display dialog "Save changes to the script’s data before quitting?" ¬
  28.             with icon caution ¬
  29.             buttons {"Don’t Save", "Cancel", "Save"} ¬
  30.             default button "Save"
  31.         --If the user presses Cancel, the script will fail silently,
  32.         --and the application's Quit handler will not run.
  33.         if the button returned of result is not "Save" then
  34.             copy OriginalData to MyData --Restore the backup
  35.         end if
  36.         set modified to false
  37.     end if
  38.     copy 0 to OriginalData --No need to store 2 copies in the file!
  39.     continue quit --This makes the application actually quit
  40. end quit